home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / SeaInvaders.dxr / 00006_Bullet Scripts.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  3.6 KB  |  120 lines

  1. global bulletData, bulletSO, maxBullets, playerLocData, enemyData
  2.  
  3. on initializeBullets
  4.   bulletData = []
  5.   repeat with wBullet = 1 to maxBullets
  6.     wSprite = wBullet + bulletSO
  7.     add(bulletData, [1, point(random(5000), 3000), point(random(50) - 25, random(15)), 0, 0])
  8.     set the member of sprite wSprite to "Pearl"
  9.   end repeat
  10.   bulletData[1][1] = 1
  11. end
  12.  
  13. on updateBulletDisplay
  14.   totalBullets = 0
  15.   repeat with wScan = 1 to count(bulletData)
  16.     if bulletData[wScan][1] = 0 then
  17.       totalBullets = totalBullets + 1
  18.     end if
  19.   end repeat
  20.   member("Pearls Display").text = string(totalBullets)
  21. end
  22.  
  23. on launchBullet
  24.   validSlot = 0
  25.   totalBullets = 0
  26.   repeat with wScan = 1 to count(bulletData)
  27.     if bulletData[wScan][1] = 0 then
  28.       if validSlot = 0 then
  29.         validSlot = wScan
  30.       end if
  31.     end if
  32.   end repeat
  33.   if validSlot <> 0 then
  34.     spawnloc = point(playerLocData[2], 3650)
  35.     targloc = the mouseLoc * 10
  36.     fireAim = findAngle(spawnloc, targloc)
  37.     locY = cos(fireAim * PI / 180) * -200
  38.     locX = sin(fireAim * PI / 180) * 200
  39.     bulletData[validSlot] = [1, spawnloc, point(locX, locY), 1, 1]
  40.     updateBulletDisplay()
  41.     playSound("Shoot", 4)
  42.   end if
  43. end
  44.  
  45. on moveBullets
  46.   global rendEnemyAsunder
  47.   repeat with wBullet = 1 to count(bulletData)
  48.     wSprite = wBullet + bulletSO
  49.     if bulletData[wBullet][1] = 1 then
  50.       bulletData[wBullet][4] = bulletData[wBullet][4] + 1
  51.       bLoc = bulletData[wBullet][2]
  52.       bSpeed = bulletData[wBullet][3]
  53.       bSpeed = bSpeed + point(0, 2)
  54.       if bLoc[1] > 5800 then
  55.         bSpeed[1] = 0 - abs(bSpeed[1])
  56.       else
  57.         if bLoc[1] < 0 then
  58.           bSpeed[1] = abs(bSpeed[1])
  59.         end if
  60.       end if
  61.       if bLoc[2] > 3800 then
  62.         bSpeed[2] = 0 - (abs(bSpeed[2]) / 3)
  63.         if bSpeed[2] > -25 then
  64.           bSpeed[2] = 0
  65.         end if
  66.         bSpeed[1] = bSpeed[1] / 2
  67.         bLoc[2] = 3800
  68.       end if
  69.       bulletData[wBullet][3] = bSpeed
  70.       bLoc = bLoc + bSpeed
  71.       bulletData[wBullet][2] = bLoc
  72.       if findDistance(point(0, 0), bSpeed) > 20 then
  73.         if random(3) = 1 then
  74.           addparticle(bLoc, 0, 1)
  75.         end if
  76.       end if
  77.       revertToplayer = 0
  78.       if bulletData[wBullet][4] > 10 then
  79.         grabDist = findDistance(point(playerLocData[2], 3650), bulletData[wBullet][2])
  80.         if grabDist <= 300 then
  81.           revertToplayer = 1
  82.         end if
  83.       end if
  84.       playRendAsunderSOund = 0
  85.       rendEnemyAsunder = 0
  86.       if bulletData[wBullet][5] = 1 then
  87.         repeat with wEnemy = 1 to count(enemyData)
  88.           if (rendEnemyAsunder = 0) and (enemyData[wEnemy][1] = 1) then
  89.             if [1, 1, 1, 0, 0, 0][enemyData[wEnemy][2]] = 1 then
  90.               rendDist = findDistance(enemyData[wEnemy][3], bulletData[wBullet][2])
  91.               if rendDist <= 175 then
  92.                 rendEnemyAsunder = wEnemy
  93.                 playRendAsunderSOund = 1
  94.               end if
  95.             end if
  96.           end if
  97.         end repeat
  98.       end if
  99.       if rendEnemyAsunder <> 0 then
  100.         enemyData[rendEnemyAsunder][5] = enemyData[rendEnemyAsunder][5] + 1
  101.         bulletData[wBullet][5] = 0
  102.         bulletData[wBullet][3] = point(0, 0) - (bulletData[wBullet][3] / 4)
  103.         repeat with wEffect = 1 to 6
  104.           addparticle(bulletData[wBullet][2], 0, 2)
  105.         end repeat
  106.       end if
  107.       if revertToplayer = 1 then
  108.         bulletData[wBullet][1] = 0
  109.         set the loc of sprite wSprite to point(-50, -50)
  110.         updateBulletDisplay()
  111.         next repeat
  112.       end if
  113.       set the loc of sprite wSprite to bLoc / 10
  114.     end if
  115.   end repeat
  116.   if playRendAsunderSOund = 1 then
  117.     playSound("Hit Enemy", 2)
  118.   end if
  119. end
  120.